package com.woniuxy.controller;

import com.woniuxy.util.MinioUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.InputStream;

/**
 * @ClassName MinioController
 * @Description minio上传下载文件控制器
 * @Author Joker
 * @Version 1.0.0
 **/
@RestController
@RequestMapping("/minio")
@Api(tags = "文件上传下载控制器")
@CrossOrigin
public class MinioController {
    @Resource
    private MinioUtil minioUtil;
    /**
     * @Author Joker
     * @Description 上传文件
     * @Date  
     * @Param [file]
     * @Return void
     **/
    @ApiOperation("上传文件")
    @PostMapping("/upload")
    public void upload(MultipartFile file) throws Exception{
        InputStream inputStream = file.getInputStream();
        String filename = file.getOriginalFilename();
        minioUtil.uploadToMinio(inputStream, filename);
        //String s = minioUtil.uploadToMinio(inputStream, filename);
        //http://47.108.78.59:9000/pawnfour/2021-05-14/039ce4f2fb4449c6ab5e1d506dec9412.png
        //上传至t_dealtime表中file_address的字段内容
    }

//    @DeleteMapping
//    public void delete(MultipartFile file){
//        String fileName = file.getOriginalFilename();
//        minioUtil.delete(fileName);
//    }
}
